home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 045a / btp15.zip / CRUNCH1.PAS < prev    next >
Pascal/Delphi Source File  |  1991-11-08  |  2KB  |  85 lines

  1. PROGRAM Crunch1;              { (c) 1991 John C. Leon   last updated 11/4/91 }
  2.  
  3. {Handles ONLY standard, fixed length Btrieve files.}
  4.  
  5. {$IFDEF production} {$D-,R-,L-,S-} {$ENDIF}
  6.  
  7. USES
  8.    BTP;
  9.  
  10. VAR
  11.    OrgName, CopyName : string[79];
  12.    OrgFile, CopyFile : PBFixed;
  13.    Counter           : word;
  14.  
  15. (* Begin MAIN program code *)
  16. (* ------------------------------------------------------------------------ *)
  17. BEGIN
  18.  
  19. write('Name of file to copy from: ');
  20. readln(OrgName);
  21. for Counter := 1 to length(OrgName) do
  22.    OrgName[Counter] := upcase(OrgName[Counter]);
  23.  
  24. write('Name of file to create and populate from file ''', OrgName,''': ');
  25. readln(CopyName);
  26. for Counter := 1 to length(CopyName) do
  27.    CopyName[Counter] := upcase(CopyName[Counter]);
  28.  
  29. { Open original file in read only mode }
  30. OrgFile := new(PBFixed, Init(OrgName, ReadOnly));
  31.  
  32. if BStatus <> Zero then
  33.    writeln('Error opening ', OrgName)
  34.    else
  35.  
  36.    begin                     {if original file exists and no error on open op}
  37.  
  38.    if OrgFile^.NumRecs = 0 then            {don't proceed if empty file}
  39.       begin
  40.       writeln('No records in ', OrgName, '.  CRUNCH1 aborted.');
  41.       halt;
  42.       end;
  43.  
  44.    if (OrgFile^.Specs.FileFlags and 1) = 1 then    {don't do var length files}
  45.       begin
  46.       writeln(OrgName, ' is a variable length file.  Can''t process.');
  47.       halt;
  48.       end;
  49.  
  50.    {Create copy of original, using precisely the same specs.}
  51.    BStatus := CloneFile(OrgName, CopyName);
  52.    if BStatus = Zero then
  53.       writeln(CopyName, ' created successfully.')
  54.       else
  55.       begin
  56.       writeln('Error creating ', CopyName, '.  Status = ', BStatus, '.');
  57.       halt;
  58.       end;
  59.  
  60.    {Open new copy of file in accelerated mode.}
  61.    CopyFile := new(PBFixed, Init(CopyName, Accel));
  62.  
  63.    {Main loop...read a record, write a record.}
  64.    for Counter:= 1 to OrgFile^.NumRecs do
  65.       begin
  66.       BStatus := OrgFile^.BT(BStepNext, Zero);
  67.       CopyFile^.DBuffer := OrgFile^.DBuffer;
  68.       BStatus := CopyFile^.BT(BInsert, Zero);
  69.       if (Counter MOD 5) = 0 then
  70.          writeln('Inserted total of ', Counter, ' records');
  71.       end;
  72.    if (Counter MOD 5) <> 0 then
  73.       writeln('Inserted total of ', Counter, ' records');
  74.    writeln('DONE...');
  75.  
  76.    BStatus := OrgFile^.Close;
  77.    BStatus := CopyFile^.Close;
  78.  
  79.    dispose(OrgFile, Done);
  80.    dispose(CopyFile, Done);
  81.  
  82.    end;  {if BStatus <> Zero}
  83.  
  84. END.
  85.